#include "gm_sc_digest.h"

#include "../../gm_api/skfapi_ex_defs.h"

gm_sc_digest::gm_sc_digest(void)
{
	_isHardware = 1;
	init_handle(DIGEST_HANDLE);
}

gm_sc_digest::~gm_sc_digest(void)
{
}

gm_sc_digest::gm_sc_digest(ULONG algid)
{
	_algid = algid;
	_isHardware = 1;
	init_handle(DIGEST_HANDLE);
}

void gm_sc_digest::use_software_engine()
{
	_isHardware = 0;
}

ULONG gm_sc_digest::get_block_size()
{
	return gm_sc_digest::get_block_size(_algid);
}

ULONG gm_sc_digest::get_block_size(ULONG algId)
{
	ULONG blockSize = 0;
	switch(algId)
	{
	case SGD_MD5:
		{
			blockSize = 16;
		}
		break;
	case SGD_SHA1:
		blockSize = 20;
		break;
	case SGD_SHA256:
	case SGD_SM3:
		blockSize = 32;
	}
	return blockSize;
}

ULONG gm_sc_digest::get_dev_alg_id(ULONG algId)
{
	if(algId == SGD_SHA256)
	{
		algId = 3;
	}

	return algId;
}